package com.healthtop.web;

import com.healthtop.common.Page;
import com.healthtop.common.Views;
import com.healthtop.dto.XsArticleCategoryDto;
import com.healthtop.service.DIYService;
import com.healthtop.service.XsArticleCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/articleCategory")
public class XsArticleCategoryController {

    @Autowired
    private DIYService diyService;

    @Autowired
    private XsArticleCategoryService xsArticleCategoryService;

    /**
     * 文章类目列表
     * @param page
     * @return
     */
    @RequestMapping("/list")
    public String list(Page page){
        diyService.selectXsArticleCategoryPage(page);
        return Views.XS_ARTICLE_CATEGORY_LIST;
    }

    /**
     * 进入文章类目编辑/新增
     * @param xsArticleCategoryDto
     * @return
     */
    @RequestMapping("/forward")
    public String forward(XsArticleCategoryDto xsArticleCategoryDto){
        xsArticleCategoryService.forward(xsArticleCategoryDto);
        return Views.XS_ARTICLE_CATEGORY_FORM;
    }

    /**
     * 操作文章类目
     * @param xsArticleCategoryDto
     * @return
     */
    @RequestMapping("/operate")
    public String operate(XsArticleCategoryDto xsArticleCategoryDto){
        xsArticleCategoryService.operate(xsArticleCategoryDto);
        return Views.REDIRECT_XS_ARTICLE_CATEGORY_LIST;
    }

    /**
     * 删除文章类目
     * @param xsArticleCategoryDto
     * @return
     */
    @RequestMapping("/delete")
    public String delete(XsArticleCategoryDto xsArticleCategoryDto){
        xsArticleCategoryService.delete(xsArticleCategoryDto);
        return Views.REDIRECT_XS_ARTICLE_CATEGORY_LIST;
    }

    /**
     * 获取文章类目
     * @param gameId
     * @return
     */
    @RequestMapping("/selectArticleCategoryByGameId")
    @ResponseBody
    public List selectArticleCategoryByGameId(Long gameId){
        return xsArticleCategoryService.selectByGameId(gameId);
    }
}
